package com.hd123.rumba.gwt.widget.client;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class AsyncCallDialog extends DialogBox implements ClickListener {
  private Label message;
  private Button okButton;

  public static AsyncCallDialog show(String message) {
    AsyncCallDialog dialog = new AsyncCallDialog();
    dialog.setText("执行中");
    dialog.message.setText(message);
    dialog.show();
    dialog.center();
    return dialog;
  }

  public void confirmSuccess(String message) {
    setText("成功");
    this.message.setText(message);
    okButton.setVisible(true);
    center();
  }

  public void confirmFail(String message) {
    setText("失败");
    setStyleName("gwt-ErrorDialogBox");
    this.message.setText(message);
    okButton.setVisible(true);
    center();
  }

  private AsyncCallDialog() {
    super(false, true);
    DockPanel dock = new DockPanel();
    dock.setSpacing(4);
    dock.setWidth("200px");
    dock.add(message = new Label(), DockPanel.CENTER);
    dock.add(okButton = new Button(" 确定 ", this), DockPanel.SOUTH);
    dock.setCellHorizontalAlignment(okButton, DockPanel.ALIGN_RIGHT);
    okButton.setVisible(false);
    setWidget(dock);
  }

  public void onClick(Widget sender) {
    hide();
  }
}
